<template>
  <div style="width: 100%">
    <a-card class="eip-admin-card-small" :bordered="false">
      <eip-search
        :option="table.search.option"
        @search="tableSearch"
      ></eip-search>
    </a-card>

    <a-card class="eip-admin-card-small">
      <vxe-toolbar
        ref="toolbar"
        custom
        print
        export
        :refresh="{ query: tableInit }"
      >
        <template v-slot:buttons>
          <eip-toolbar @onload="toolbarOnload"></eip-toolbar>
        </template>
      </vxe-toolbar>
      <a-spin :spinning="table.loading">
        <vxe-table
          ref="table"
          id="workflowcommentlist"
          size="small"
          :seq-config="{
            startIndex: (table.page.param.current - 1) * table.page.param.size,
          }"
          :print-config="{}"
          :export-config="{}"
          :height="table.height"
          :data="table.data"
          :tooltip-config="{ showAll: true, contentMethod: tableTooltip }"
        >
          <vxe-table-column
            type="checkbox"
            width="60"
            align="center"
          ></vxe-table-column>
          <vxe-table-column
            type="seq"
            title="序号"
            width="60"
          ></vxe-table-column>
          <vxe-table-column
            field="sn"
            title="流水号"
            width="150"
          ></vxe-table-column>
          <vxe-table-column
            field="title"
            title="流程名称"
            min-width="120"
          ></vxe-table-column>

          <vxe-table-column
            field="createTime"
            title="创建时间"
            width="150"
          ></vxe-table-column>
          <vxe-table-column
            field="createUserName"
            title="创建人"
            width="100"
          ></vxe-table-column>

          <vxe-table-column
            field="statusRemark"
            title="状态描述"
            showOverflow="ellipsis"
            width="150"
          ></vxe-table-column>
          <vxe-table-column
            field="receiveTime"
            title="任务状态"
            align="center"
            width="100"
            ><template v-slot="{ row }">
              <a-tag v-if="row.status == 4" color="#108ee9"> 处理中 </a-tag>
              <a-tag v-if="row.status == 6" color="#2db7f5"> 完成 </a-tag>
              <a-tag v-if="row.status == 8" color="#c21401"> 暂停 </a-tag>
              <a-tag v-if="row.status == 12" color="#90cf5b"> 退回 </a-tag>
              <a-tag v-if="row.status == 14" color="#00af57"> 取消 </a-tag>
              <a-tag v-if="row.status == 16" color="#ff1e02"> 拒绝 </a-tag>
              <a-tag v-if="row.status == 18" color="#0071be"> 知会已阅 </a-tag>
              <a-tag v-if="row.status == 20" color="#00215f"> 已阅 </a-tag>
              <a-tag v-if="row.status == 22" color="#72349d"> 召回 </a-tag>
              <a-tag v-if="row.status == 24" color="#e2534d"> 删除 </a-tag>
            </template></vxe-table-column
          >
          <vxe-table-column
            field="urgency"
            title="紧急程度"
            width="80px"
            align="center"
          >
            <template v-slot="{ row }">
              <a-tag v-if="row.urgency == 0" color="#108ee9"> 正常 </a-tag>
              <a-tag v-if="row.urgency == 2" color="#87d068"> 重要 </a-tag>
              <a-tag v-if="row.urgency == 4" color="red"> 紧急 </a-tag>
            </template>
          </vxe-table-column>
          <vxe-table-column
            title="操作"
            align="center"
            fixed="right"
            width="160px"
          >
            <template #default="{ row }">
              <a-tooltip
                @click="tableUpdateRow(row)"
                title="编辑"
                v-if="visible.update"
              >
                <label class="text-eip eip-cursor-pointer">编辑</label>
              </a-tooltip>
              <a-divider type="vertical" v-if="visible.update" />
              <a-tooltip
                title="删除"
                v-if="visible.del"
                @click="tableDelRow(row)"
              >
                <label class="text-red eip-cursor-pointer">删除</label>
              </a-tooltip>
            </template>
          </vxe-table-column>
        </vxe-table>

        <a-pagination
          class="padding-top-sm float-right"
          v-model="table.page.param.current"
          size="small"
          show-size-changer
          show-quick-jumper
          showSizeChanger
          showQuickJumper
          :page-size-options="table.page.sizeOptions"
          :show-total="(total) => `共 ${total} 条`"
          :page-size="table.page.param.size"
          :total="table.page.total"
          @change="tableInit"
          @showSizeChange="tableSizeChange"
        ></a-pagination>
      </a-spin>
    </a-card>
  </div>
</template>

<script>
import { query } from "@/services/workflow/monitor/list";
import eipSearch from "@/pages/common/usercontrol/eip-search";
import eipToolbar from "@/pages/common/usercontrol/eip-toolbar";
import XEUtils from "xe-utils";
import { selectTableRow, deleteConfirm } from "@/utils/util";
export default {
  data() {
    return {
      table: {
        page: {
          param: {
            current: 1,
            size: this.eipPage.size,
            sord: "desc",
            sidx: "CreateTime",
            filters: "",
          },
          total: 0,
          sizeOptions: this.eipPage.sizeOptions,
        },
        loading: true,
        data: [],
        height: this.eipHeaderHeight() - 156 + "px",
        search: {
          option: {
            num: 6,
            config: [
              {
                field: "processInstance.Sn",
                op: "cn",
                placeholder: "请输入流水号",
                title: "流水号",
                value: "",
                type: "text",
              },
              {
                field: "processInstance.Title",
                op: "cn",
                placeholder: "请输入流程名称",
                title: "流程名称",
                value: "",
                type: "text",
              },
              {
                field: "processInstance.StatusRemark",
                op: "cn",
                placeholder: "请输入状态描述",
                title: "状态描述",
                value: "",
                type: "text",
              },
            ],
          },
        },
      },
      visible: {
        update: true,
        del: true,
      },
    };
  },
  components: { eipSearch, eipToolbar },
  created() {
    this.tableInit();
  },
  mounted() {
    this.$refs.table.connect(this.$refs.toolbar);
  },
  methods: {
    /**
     * 悬浮显示
     */
    tableTooltip({ type, column, row, items, _columnIndex }) {
      const { property } = column;
      if (row) {
        return row[property];
      }
      return null;
    },

    /**
     * 流程意见查询
     */
    tableSearch(filters) {
      this.table.page.param.current = 1;
      this.table.page.param.filters = filters;
      this.tableInit();
    },

    //初始化流程意见数据
    tableInit() {
      let that = this;
      that.table.loading = true;
      query(that.table.page.param).then(function (result) {
        if (result.code == that.eipResultCode.success) {
          that.table.data = result.data;
          that.table.page.total = result.count;
        }
        that.table.loading = false;
      });
    },
    /**
     *数量改变
     */
    tableSizeChange(current, pageSize) {
      this.table.page.param.size = pageSize;
      this.tableInit();
    },

    /**
     * 修改
     */
    tableUpdateRow(row) {
      this.edit.commentId = row.commentId;
      this.edit.title = "流程意见配置-" + row.content;
      this.edit.visible = true;
    },
    /**
     * 删除
     */
    tableDelRow(row) {
      let that = this;
      deleteConfirm(
        "流程意见配置【" + row.content + "】" + that.eipMsg.delete,
        function () {
          that.$message.loading(that.eipMsg.delloading);
          del({ id: row.commentId }).then((result) => {
            if (result.code == that.eipResultCode.success) {
              that.reload();
            }
            that.$message.destroy();
            that.$message.success(result.msg);
          });
        },
        that
      );
    },

    /**
     * 新增
     */
    add() {
      this.edit.commentId = null;
      this.edit.title = "新增流程意见配置";
      this.edit.visible = true;
    },

    /**
     * 修改
     */
    update() {
      let that = this;
      selectTableRow(
        that.$refs.table,
        function (row) {
          that.edit.commentId = row.commentId;
          that.edit.title = "流程意见配置-" + row.content;
          that.edit.visible = true;
        },
        that
      );
    },

    /**
     * 删除
     */
    del() {
      let that = this;
      selectTableRow(
        that.$refs.table,
        function (rows) {
          //提示是否删除
          deleteConfirm(
            that.eipMsg.delete,
            function () {
              //加载提示
              that.$message.loading(that.eipMsg.delloading);
              let ids = XEUtils.map(rows, (item) => item.commentId);
              del({ id: ids.join(",") }).then((result) => {
                if (result.code == that.eipResultCode.success) {
                  that.reload();
                }
                that.$message.destroy();
                that.$message.success(result.msg);
              });
            },
            that
          );
        },
        that,
        false
      );
    },

    //提示状态信息
    perateStatus(result) {
      if (result.code === this.eipResultCode.success) {
        this.reload();
      }
    },

    /**
     * 重新加载
     */
    reload() {
      this.table.page.param.current = 1;
      this.tableInit();
    },

    /**
     * 权限意见加载完毕
     */
    toolbarOnload(comments) {
      this.visible.update =
        comments.filter((f) => f.method == "update").length > 0;
      this.visible.del = comments.filter((f) => f.method == "del").length > 0;
    },
  },
};
</script>

<style lang="less" scoped>
</style>
